<?php

class Model_Categories extends Model {
    
    private $table_name = 'categories';


    public function getMainCategories() {
        $sql = "SELECT c.* 
                    FROM (
                        {$this->table_name} as c
                    )
                    WHERE (
                        ISNULL (c.parent_id)
                    )";
        
        return $this->db->query($sql)->fetchAll();
    }
    
    
    
    public function getSubCategories($category_id) {
        $sql = "SELECT c.* 
                    FROM (
                        {$this->table_name} as c
                    )
                    WHERE (
                        c.parent_id = {$category_id}
                    )";
        
        return $this->db->query($sql)->fetchAll();
    }
    
}